﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Invoicing.AJAX
{
    /// <summary>
    /// RoleInfo 的摘要说明
    /// </summary>
    public class RoleInfo : IHttpHandler
    {
        private HttpRequest Req = HttpContext.Current.Request;
        private ZY.BLL.Tab_RoleInfo dal = new ZY.BLL.Tab_RoleInfo();
        public void ProcessRequest(HttpContext context)
        {
            if (Req["action"]!=null)
            {

                string action = Req["action"].ToString();

                switch (action)
                {
                    case "add":
                        #region 执行添加操作
                        try
                        {
                            ZY.Model.Tab_RoleInfo model = new ZY.Model.Tab_RoleInfo();
                            model.r_createtime = DateTime.Now;
                            model.r_lasttime = DateTime.Now;
                            model.r_leve = int.Parse(Req["rlevel"].ToString());
                            model.r_name = Req["txtroleName"].ToString();
                            model.r_note = Req["txtRoleNote"].ToString();
                            model.r_upid = 0;// int.Parse(Req[""].ToString());
                            dal.Add(model);
                            context.Response.Write(Pubs.AjaxHandle.AjaxPress("200", "添加成功!", "rolelist", "sys/RoleInfo.aspx"));


                        }
                        catch (Exception ex)
                        {
                            context.Response.Write(Pubs.AjaxHandle.AjaxPress("300", ex.Message));

                           
                        }
                        #endregion
                        break;
                    case "edit":
                        #region 执行编辑操作

                        if (Req["reid"]!=null)
                        {
                            try
                            {
                                //ZY.Model.Tab_RoleInfo upmodel = dal.GetModel(int.Parse(Req["reid"].ToString()));
                                //upmodel.r_leve = int.Parse(Req["rlevel"].ToString());
                                //upmodel.r_name = Req["txtroleName"].ToString();
                                //upmodel.r_note = Req["txtRoleNote"].ToString();
                                //upmodel.r_lasttime = DateTime.Now;
                                dal.Proc_RoleEdit(int.Parse(Req["rlevel"].ToString()), Req["treeids"].ToString(), Req["txtroleName"].ToString(), Req["txtRoleNote"].ToString(), int.Parse(Req["reid"].ToString()));
                                context.Response.Write(Pubs.AjaxHandle.AjaxPress("200", "修改成功!", "rolelist", "sys/RoleInfo.aspx"));
    
                            }
                            catch (Exception ex)
                            {

                                context.Response.Write(Pubs.AjaxHandle.AjaxPress("300", ex.Message));
                            }
                       
                            
                        }



                        #endregion
                        break;
                    case "del":
                        #region 执行删除操作
                        string ids = Req["ids"].ToString();
                        string[] param = ids.Split(',');

                        foreach (var item in param)
                        {

                            try
                            {
                                if (item != null)
                                {
                                    dal.Delete(int.Parse(item));
                                }
                            }
                            catch (Exception ex)
                            {

                                context.Response.Write(Pubs.AjaxHandle.AjaxPress("300",ex.Message));

                            }

                        }

                        context.Response.Write(Pubs.AjaxHandle.AjaxPressTodo("200", "删除成功"));

                        #endregion 




                        break;
                    default:
                        break;
                }

                
            }


           
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}